{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import geopandas\n",
    "import numpy as np\n",
    "from sklearn.cluster import AffinityPropagation\n",
    "from sklearn.cluster import KMeans\n",
    "from sklearn import preprocessing, datasets\n",
    "import matplotlib.pyplot as plt\n",
    "import csv\n",
    "import os\n",
    "from sklearn.metrics import pairwise_distances_argmin\n",
    "import pandas as pd\n",
    "from scipy.spatial.distance import cdist,pdist\n",
    "import itertools\n",
    "from mpl_toolkits.basemap import Basemap\n",
    "import math\n",
    "from scipy import stats\n",
    "from scipy.sparse import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'/Users/qiancao/Documents'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.getcwd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "g = open('file.csv')\n",
    "csv_f = csv.reader(g,None)\n",
    "next(csv_f,None)\n",
    "\n",
    "XX=[]\n",
    "for row in csv_f:\n",
    "    row[0],row[1],row[2] = float(row[0]),float(row[1]),float(row[2])\n",
    "    XX.append(row)\n",
    "\n",
    "XX = np.array(XX)\n",
    "X=XX[:,[0,1]]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## I. plotting the sites status quo\n",
    "#### Finding outstanding sites, like Indonesia has sites plotted in the ocean"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.figure(figsize=(12,12))\n",
    "mm = Basemap(llcrnrlon = min(X[:,0])-10,llcrnrlat = min(X[:,1])-10, urcrnrlon = max(X[:,0])+10,urcrnrlat = max(X[:,1])+10)\n",
    "mm.drawmapboundary(fill_color = '#A6CAE0',linewidth = 0)\n",
    "mm.fillcontinents(color = 'grey', alpha = 0.4, lake_color = 'grey')\n",
    "mm.drawcoastlines(linewidth = 0.5,color = 'white')\n",
    "\n",
    "plt.scatter(X[:,0],X[:,1],s=80,cmap='viridis')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## II. Clustering w/ Center of Gravity Model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Assign random clusters as hyperparameter initially, will be optimized by model iteration later\n",
    "\n",
    "## k: number of clusters\n",
    "## X: all sites array\n",
    "## sla: period from despatching to destination\n",
    "## kmh: kilometer per hour for driving speed\n",
    "## h: driver driving time per day\n",
    "## q: sites coverage by such policy (percent)\n",
    "\n",
    "def model_Kmeans(k,X,sla=2,kmh=60,h=8,q=.9):\n",
    "    def find_clusters (X, n_clusters, rseed=2):\n",
    "        #1.Randomly choose clusters\n",
    "        rng = np.random.RandomState(rseed)\n",
    "        i = rng.permutation(X.shape[0])[:n_clusters]\n",
    "        centers = X[i].astype(float)\n",
    "        \n",
    "        while True:\n",
    "            #2a. Assign labels based on closest center: if 5 centers, then labels have 0,1,2,3,4\n",
    "            labels = pairwise_distances_argmin(X,centers)\n",
    "            #2b. Find new centers from means of points\n",
    "            new_centers = np.array([X[labels ==i].mean(0) for i in range(n_clusters)])\n",
    "            #2c. Check for convergence\n",
    "            if np.all(centers == new_centers):\n",
    "                break\n",
    "            centers = new_centers\n",
    "        return centers, labels\n",
    "    centers,labels = find_clusters(X,k)\n",
    "    # So far the centers are fixed, regardless random centers changes.\n",
    "    \n",
    "    # Add each coordination to clusters, which is a dictionary {item(label), X_coordinate}\n",
    "    clusters = {}\n",
    "    n=0\n",
    "    for item in labels:\n",
    "        if item in clusters:\n",
    "            clusters[item].append(X[n])\n",
    "        else:\n",
    "            clusters[item] = [X[n]]\n",
    "        n+=1\n",
    "        \n",
    "    ### Build distance matrix\n",
    "    def haversine(lon1,lat1,lon2,lat2):\n",
    "        \"\"\"\n",
    "        Calculate the great circle distance between 2 points\n",
    "        on the earch (specifid in decimal degree)\n",
    "        \"\"\"\n",
    "        # Convert decimal degree to radians\n",
    "        lon1,lat1,lon2,lat2 = map(np.radians,[lon1,lat1,lon2,lat2])\n",
    "        # Haversine formula\n",
    "        dlon = lon2-lon1\n",
    "        dlat = lat2-lat1\n",
    "        a = np.sin(dlat/2)**2 + np.cos(lat1) * np.cos(lat2) * np.sin(dlon/2)**2\n",
    "        c = 2 * np.math.asin(np.sqrt(a))\n",
    "        #r = 6371 # Radius of earth in kilometers. Use 3956 for miles\n",
    "        km = 6367 * c\n",
    "        return km\n",
    "    \n",
    "    a=[]\n",
    "    b=[]\n",
    "    \n",
    "    for i in range (k):\n",
    "        for j in (clusters[i]):\n",
    "            a.append(j)\n",
    "            \n",
    "    for m in range(k):\n",
    "        for n in range (len(clusters[m])):\n",
    "            b.append(centers[m])\n",
    "            \n",
    "    matrix1 = pd.DataFrame(a,columns=['CENT_LON','CENT_LAT'])\n",
    "    matrix2 = pd.DataFrame(b,columns=['CLST_LON','CLST_LAT'])\n",
    "    matrix  = pd.concat([matrix1,matrix2],axis=1,join_axes=[matrix1.index])\n",
    "    \n",
    "    for i in matrix.index:\n",
    "        matrix.loc[i,'CENT_SITE_DIST'] = 1.19*haversine(matrix.loc[i,'CENT_LON'],matrix.loc[i,'CENT_LAT'],matrix.loc[i,'CLST_LON'],matrix.loc[i,'CLST_LAT'])\n",
    "    \n",
    "    # Drop duplicated site for avoiding dulicate CBM mapping\n",
    "    matrix.drop_duplicates(subset=['CENT_LON','CENT_LAT'],inplace=True)\n",
    "    matrix.reset_index(drop = True,inplace = True)\n",
    "    \n",
    "    # Processing the dataset for adding volume\n",
    "    df_v = pd.DataFrame(XX,columns=['ORG_LON','ORG_LAT','CBM'])\n",
    "    df_v.CBM = df_v.CBM.apply(lambda x: float(x))\n",
    "    df_v = df_v.groupby(['ORG_LON','ORG_LAT'])['CBM'].sum()\n",
    "    df_gpv = pd.DataFrame(df_v).reset_index()\n",
    "    \n",
    "    matrix_V = pd.merge(matrix,df_gpv,left_on=['CENT_LON','CENT_LAT'],right_on=['ORG_LON','ORG_LAT'])\n",
    "    matrix_V.drop(['CENT_LON','CENT_LAT'],axis = 1, inplace = True)\n",
    "    \n",
    "    # The center-of-gravity method\n",
    "    # Cx = Sum(DixVi)/Sum(Vi) AND Cy = Sum(DiyVi)/Sum(Vi)\n",
    "    # Parameters: \n",
    "    # Cx--重心的X坐标 \n",
    "    # Cy--重心的Y坐标\n",
    "    # Dix--第i个地点的X坐标\n",
    "    # Diy--第i个地点的Y坐标\n",
    "    # Vi--运到第i个地点，或从第i地点运出的货物量\n",
    "\n",
    "    matrix_V_gb = matrix_V.groupby(['CLST_LON','CLST_LAT'])\n",
    "    \n",
    "    # Calculating the Center of Gravity\n",
    "    def COG(gp):\n",
    "        LON = sum(np.multiply(gp['ORG_LON'],gp['CBM']))/sum(gp['CBM'])\n",
    "        LAT = sum(np.multiply(gp['ORG_LAT'],gp['CBM']))/sum(gp['CBM'])\n",
    "        return LON,LAT\n",
    "    \n",
    "    # Adding the new-COG to the clusted diagram list\n",
    "    Re_center = matrix_V_gb.apply(lambda grp: COG(grp)[0])\n",
    "    matrix_COG = pd.DataFrame(Re_center).reset_index()\n",
    "    matrix_COG.columns = ['CLST_LON','CLST_LAT','COG_LON']\n",
    "    centerList=matrix_V_gb.apply(lambda grp: COG(grp)[1]).values\n",
    "    matrix_COG['COG_LAT'] = centerList\n",
    "    \n",
    "    matrix_New = pd.merge(matrix_V,matrix_COG, on=['CLST_LON','CLST_LAT'],how = 'left')\n",
    "    matrix_New = matrix_New[['ORG_LON','ORG_LAT','COG_LON','COG_LAT','CBM']]\n",
    "    \n",
    "    for i in matrix_New.index:\n",
    "        matrix_New.loc[i,'DISTANCE']= 1.19*haversine(matrix_New.loc[i,'ORG_LON'],matrix_New.loc[i,'ORG_LAT'],matrix_New.loc[i,'COG_LON'],matrix_New.loc[i,'COG_LAT'])\n",
    "        \n",
    "        \n",
    "    # Sort distance ascending by clusters\n",
    "    m_min = matrix_New.sort_values(by=['COG_LON','COG_LAT','DISTANCE']).groupby(['COG_LON','COG_LAT']).head(1)\n",
    "    \n",
    "    # Apply closest site to the Center Location\n",
    "    def replace_COG(df):\n",
    "        test=m_min[(m_min.COG_LON == df['COG_LON']) & (m_min.COG_LAT == df['COG_LAT'])]\n",
    "        df['COG_LON']=test['ORG_LON']\n",
    "        df['COG_LAT']=test['ORG_LAT']\n",
    "        return df\n",
    "    \n",
    "    matrix_New.apply(replace_COG,axis=1)\n",
    "    \n",
    "    # Stacking LON and LAT to one array\n",
    "    Centroids_New = np.column_stack((matrix_New.COG_LON.unique(),matrix_New.COG_LAT.unique()))\n",
    "    SLA = matrix_New.groupby(['COG_LON','COG_LAT'])['DISTANCE'].quantile(q)/kmh/h\n",
    "    \n",
    "    # Calculating the SLA\n",
    "    matrix_New['SLA'] = matrix_New['DISTANCE'].apply(lambda x: math.ceil(float(x/kmh)/h))\n",
    "    matrix_New.sort_values(['COG_LON','COG_LAT','SLA'],ascending = [False,False,True],inplace = True)\n",
    "    \n",
    "    percentile = stats.percentileofscore(matrix_New['SLA'],sla+1,kind='rank')\n",
    "    return SLA, percentile,centers,matrix_New,Centroids_New,labels\n",
    "        "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## III. Run Model: finding conditions complying with required SLA:\n",
    "### Step1. Initialization: \n",
    "Hyperparameter: SLA limit, Tranportation speed, Working Hours, Coverage by Percent"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "SLA = 0.5\n",
    "kmh = 60\n",
    "h = 8\n",
    "q = 0.9"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step2. Find out proper K of clusters satisfying SLA required"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 centers 0.5 day(s) covers 5.9 % sites\n",
      "4.36 day(s) covers 90.0 % sites\n",
      "2 centers 0.5 day(s) covers 23.5 % sites\n",
      "4.44 day(s) covers 90.0 % sites\n",
      "3 centers 0.5 day(s) covers 26.6 % sites\n",
      "2.79 day(s) covers 90.0 % sites\n",
      "4 centers 0.5 day(s) covers 37.7 % sites\n",
      "2.79 day(s) covers 90.0 % sites\n",
      "5 centers 0.5 day(s) covers 49.9 % sites\n",
      "2.59 day(s) covers 90.0 % sites\n",
      "6 centers 0.5 day(s) covers 54.8 % sites\n",
      "2.57 day(s) covers 90.0 % sites\n",
      "7 centers 0.5 day(s) covers 58.9 % sites\n",
      "2.22 day(s) covers 90.0 % sites\n",
      "8 centers 0.5 day(s) covers 63.0 % sites\n",
      "1.88 day(s) covers 90.0 % sites\n",
      "9 centers 0.5 day(s) covers 72.1 % sites\n",
      "1.88 day(s) covers 90.0 % sites\n"
     ]
    }
   ],
   "source": [
    "for k in range (1,10):\n",
    "    p = model_Kmeans(k,X,SLA,kmh,h)[1]\n",
    "    s = model_Kmeans(k,X,SLA,kmh,h)[0]\n",
    "    print (k, 'centers',SLA, 'day(s) covers', round(p,1), '% sites')\n",
    "    if (max(s.values)>SLA) | (p<90):\n",
    "        print (round(max(s.values),2),'day(s) covers', q*100, '% sites')\n",
    "        continue\n",
    "    else:\n",
    "        print (round(max(s.values),2),'day(s) covers',round(p,1), '% sites')\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Generate SLA, Distance, Centers, Dataframe w/COG, Nearest Site as Center, Classes\n",
    "s,p,c,m,t,l = model_Kmeans(k,X,SLA,kmh,h)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ORG_LON</th>\n",
       "      <th>ORG_LAT</th>\n",
       "      <th>COG_LON</th>\n",
       "      <th>COG_LAT</th>\n",
       "      <th>CBM</th>\n",
       "      <th>DISTANCE</th>\n",
       "      <th>SLA</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>133</th>\n",
       "      <td>-35.0300</td>\n",
       "      <td>-8.2900</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>6825.0</td>\n",
       "      <td>321.170625</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>134</th>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>6027.0</td>\n",
       "      <td>62.492410</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>135</th>\n",
       "      <td>-37.3400</td>\n",
       "      <td>-5.1900</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>4359.0</td>\n",
       "      <td>395.855624</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136</th>\n",
       "      <td>-37.4500</td>\n",
       "      <td>-11.2696</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>1452.0</td>\n",
       "      <td>408.561023</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>138</th>\n",
       "      <td>-35.0200</td>\n",
       "      <td>-8.1100</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>8267.0</td>\n",
       "      <td>322.357450</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>139</th>\n",
       "      <td>-38.8500</td>\n",
       "      <td>-6.4000</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>5781.0</td>\n",
       "      <td>296.035328</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>140</th>\n",
       "      <td>-34.8500</td>\n",
       "      <td>-8.0000</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>257.0</td>\n",
       "      <td>345.347578</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>141</th>\n",
       "      <td>-34.9156</td>\n",
       "      <td>-8.0756</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>1035.0</td>\n",
       "      <td>336.189210</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>142</th>\n",
       "      <td>-36.9101</td>\n",
       "      <td>-5.5796</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>3083.0</td>\n",
       "      <td>351.984787</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>143</th>\n",
       "      <td>-38.2657</td>\n",
       "      <td>-9.3307</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>7329.0</td>\n",
       "      <td>183.443251</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>144</th>\n",
       "      <td>-36.6166</td>\n",
       "      <td>-9.4166</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>5408.0</td>\n",
       "      <td>198.765999</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>145</th>\n",
       "      <td>-39.3000</td>\n",
       "      <td>-6.3600</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>9392.0</td>\n",
       "      <td>338.870422</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>146</th>\n",
       "      <td>-37.1200</td>\n",
       "      <td>-10.9000</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>3856.0</td>\n",
       "      <td>362.741005</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>147</th>\n",
       "      <td>-36.0300</td>\n",
       "      <td>-6.2200</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>8039.0</td>\n",
       "      <td>321.640214</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>148</th>\n",
       "      <td>-38.7900</td>\n",
       "      <td>-10.9696</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>4185.0</td>\n",
       "      <td>406.410855</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149</th>\n",
       "      <td>-35.3200</td>\n",
       "      <td>-7.4996</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>3106.0</td>\n",
       "      <td>297.121231</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>150</th>\n",
       "      <td>-35.2000</td>\n",
       "      <td>-8.8296</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>5770.0</td>\n",
       "      <td>310.497250</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151</th>\n",
       "      <td>-35.2600</td>\n",
       "      <td>-7.8400</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>1949.0</td>\n",
       "      <td>294.361427</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>153</th>\n",
       "      <td>-36.6700</td>\n",
       "      <td>-9.7500</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>5224.0</td>\n",
       "      <td>233.086889</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>154</th>\n",
       "      <td>-36.5800</td>\n",
       "      <td>-10.2696</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>3629.0</td>\n",
       "      <td>300.312968</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>156</th>\n",
       "      <td>-35.7300</td>\n",
       "      <td>-9.6200</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>1903.0</td>\n",
       "      <td>297.677195</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>157</th>\n",
       "      <td>-40.1900</td>\n",
       "      <td>-10.4496</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>4781.0</td>\n",
       "      <td>463.645632</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>158</th>\n",
       "      <td>-36.5000</td>\n",
       "      <td>-8.8900</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>758.0</td>\n",
       "      <td>159.015235</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>159</th>\n",
       "      <td>-35.8400</td>\n",
       "      <td>-9.4800</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>588.0</td>\n",
       "      <td>274.868006</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>160</th>\n",
       "      <td>-39.4200</td>\n",
       "      <td>-7.2296</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>178.0</td>\n",
       "      <td>283.426657</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>161</th>\n",
       "      <td>-39.3200</td>\n",
       "      <td>-7.2100</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>9476.0</td>\n",
       "      <td>272.957325</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>162</th>\n",
       "      <td>-35.2400</td>\n",
       "      <td>-5.7800</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>984.0</td>\n",
       "      <td>432.773284</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>163</th>\n",
       "      <td>-34.8761</td>\n",
       "      <td>-7.1011</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>2133.0</td>\n",
       "      <td>370.088972</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>164</th>\n",
       "      <td>-35.0000</td>\n",
       "      <td>-7.5596</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>8771.0</td>\n",
       "      <td>335.259152</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>165</th>\n",
       "      <td>-37.8000</td>\n",
       "      <td>-5.6500</td>\n",
       "      <td>-37.0700</td>\n",
       "      <td>-8.4200</td>\n",
       "      <td>917.0</td>\n",
       "      <td>337.190951</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>223</th>\n",
       "      <td>-54.6400</td>\n",
       "      <td>-16.4695</td>\n",
       "      <td>-60.1166</td>\n",
       "      <td>-12.7166</td>\n",
       "      <td>490.0</td>\n",
       "      <td>716.166503</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>226</th>\n",
       "      <td>-55.9100</td>\n",
       "      <td>-9.9000</td>\n",
       "      <td>-60.1166</td>\n",
       "      <td>-12.7166</td>\n",
       "      <td>4673.0</td>\n",
       "      <td>612.996033</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>227</th>\n",
       "      <td>-64.4166</td>\n",
       "      <td>-12.4167</td>\n",
       "      <td>-60.1166</td>\n",
       "      <td>-12.7166</td>\n",
       "      <td>8530.0</td>\n",
       "      <td>686.910950</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>228</th>\n",
       "      <td>-55.4506</td>\n",
       "      <td>-10.8173</td>\n",
       "      <td>-60.1166</td>\n",
       "      <td>-12.7166</td>\n",
       "      <td>1587.0</td>\n",
       "      <td>579.059784</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>229</th>\n",
       "      <td>-55.4600</td>\n",
       "      <td>-11.8500</td>\n",
       "      <td>-60.1166</td>\n",
       "      <td>-12.7166</td>\n",
       "      <td>9035.0</td>\n",
       "      <td>513.201940</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>331</th>\n",
       "      <td>-63.0400</td>\n",
       "      <td>-7.4639</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>5352.0</td>\n",
       "      <td>403.644727</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>336</th>\n",
       "      <td>-60.9438</td>\n",
       "      <td>-2.6208</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>6091.0</td>\n",
       "      <td>440.590296</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>337</th>\n",
       "      <td>-61.2975</td>\n",
       "      <td>-5.8122</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>3885.0</td>\n",
       "      <td>363.027081</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>339</th>\n",
       "      <td>-60.6200</td>\n",
       "      <td>-3.2896</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>6824.0</td>\n",
       "      <td>437.320106</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>341</th>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>2729.0</td>\n",
       "      <td>93.444232</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>343</th>\n",
       "      <td>-64.7000</td>\n",
       "      <td>-3.3600</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>6992.0</td>\n",
       "      <td>197.943995</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>344</th>\n",
       "      <td>-66.0916</td>\n",
       "      <td>-2.5138</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>5236.0</td>\n",
       "      <td>408.325168</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>347</th>\n",
       "      <td>-62.9239</td>\n",
       "      <td>-0.9750</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>3741.0</td>\n",
       "      <td>475.671983</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>326</th>\n",
       "      <td>-65.3499</td>\n",
       "      <td>-10.8000</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>3364.0</td>\n",
       "      <td>862.229375</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>328</th>\n",
       "      <td>-57.6500</td>\n",
       "      <td>-6.2666</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>3020.0</td>\n",
       "      <td>831.922433</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>329</th>\n",
       "      <td>-61.1277</td>\n",
       "      <td>1.8162</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>833.0</td>\n",
       "      <td>900.474063</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>330</th>\n",
       "      <td>-60.2699</td>\n",
       "      <td>-6.9838</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>5805.0</td>\n",
       "      <td>560.426870</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>332</th>\n",
       "      <td>-65.3597</td>\n",
       "      <td>-9.6954</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>1280.0</td>\n",
       "      <td>722.153924</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>333</th>\n",
       "      <td>-67.8000</td>\n",
       "      <td>-9.9666</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>3841.0</td>\n",
       "      <td>901.665920</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>334</th>\n",
       "      <td>-60.0000</td>\n",
       "      <td>-3.1000</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>2891.0</td>\n",
       "      <td>522.734324</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>335</th>\n",
       "      <td>-68.6700</td>\n",
       "      <td>-9.0700</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>5446.0</td>\n",
       "      <td>889.647581</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>338</th>\n",
       "      <td>-63.0800</td>\n",
       "      <td>-9.9396</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>1701.0</td>\n",
       "      <td>726.003764</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>340</th>\n",
       "      <td>-57.7200</td>\n",
       "      <td>-3.3896</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>8774.0</td>\n",
       "      <td>803.466441</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>342</th>\n",
       "      <td>-67.0833</td>\n",
       "      <td>-0.1332</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>6967.0</td>\n",
       "      <td>727.817230</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>346</th>\n",
       "      <td>-58.4400</td>\n",
       "      <td>-3.1400</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>2241.0</td>\n",
       "      <td>717.799949</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>348</th>\n",
       "      <td>-67.8019</td>\n",
       "      <td>-2.8727</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>9166.0</td>\n",
       "      <td>580.491363</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>349</th>\n",
       "      <td>-69.8738</td>\n",
       "      <td>-6.6600</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>1592.0</td>\n",
       "      <td>860.594888</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>350</th>\n",
       "      <td>-63.9000</td>\n",
       "      <td>-8.7500</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>1048.0</td>\n",
       "      <td>564.517094</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>327</th>\n",
       "      <td>-72.6700</td>\n",
       "      <td>-7.6300</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>4811.0</td>\n",
       "      <td>1249.259244</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>345</th>\n",
       "      <td>-60.6660</td>\n",
       "      <td>2.8161</td>\n",
       "      <td>-63.1300</td>\n",
       "      <td>-4.0800</td>\n",
       "      <td>3880.0</td>\n",
       "      <td>1045.975136</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>387 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     ORG_LON  ORG_LAT  COG_LON  COG_LAT     CBM     DISTANCE  SLA\n",
       "133 -35.0300  -8.2900 -37.0700  -8.4200  6825.0   321.170625    1\n",
       "134 -37.0700  -8.4200 -37.0700  -8.4200  6027.0    62.492410    1\n",
       "135 -37.3400  -5.1900 -37.0700  -8.4200  4359.0   395.855624    1\n",
       "136 -37.4500 -11.2696 -37.0700  -8.4200  1452.0   408.561023    1\n",
       "138 -35.0200  -8.1100 -37.0700  -8.4200  8267.0   322.357450    1\n",
       "139 -38.8500  -6.4000 -37.0700  -8.4200  5781.0   296.035328    1\n",
       "140 -34.8500  -8.0000 -37.0700  -8.4200   257.0   345.347578    1\n",
       "141 -34.9156  -8.0756 -37.0700  -8.4200  1035.0   336.189210    1\n",
       "142 -36.9101  -5.5796 -37.0700  -8.4200  3083.0   351.984787    1\n",
       "143 -38.2657  -9.3307 -37.0700  -8.4200  7329.0   183.443251    1\n",
       "144 -36.6166  -9.4166 -37.0700  -8.4200  5408.0   198.765999    1\n",
       "145 -39.3000  -6.3600 -37.0700  -8.4200  9392.0   338.870422    1\n",
       "146 -37.1200 -10.9000 -37.0700  -8.4200  3856.0   362.741005    1\n",
       "147 -36.0300  -6.2200 -37.0700  -8.4200  8039.0   321.640214    1\n",
       "148 -38.7900 -10.9696 -37.0700  -8.4200  4185.0   406.410855    1\n",
       "149 -35.3200  -7.4996 -37.0700  -8.4200  3106.0   297.121231    1\n",
       "150 -35.2000  -8.8296 -37.0700  -8.4200  5770.0   310.497250    1\n",
       "151 -35.2600  -7.8400 -37.0700  -8.4200  1949.0   294.361427    1\n",
       "153 -36.6700  -9.7500 -37.0700  -8.4200  5224.0   233.086889    1\n",
       "154 -36.5800 -10.2696 -37.0700  -8.4200  3629.0   300.312968    1\n",
       "156 -35.7300  -9.6200 -37.0700  -8.4200  1903.0   297.677195    1\n",
       "157 -40.1900 -10.4496 -37.0700  -8.4200  4781.0   463.645632    1\n",
       "158 -36.5000  -8.8900 -37.0700  -8.4200   758.0   159.015235    1\n",
       "159 -35.8400  -9.4800 -37.0700  -8.4200   588.0   274.868006    1\n",
       "160 -39.4200  -7.2296 -37.0700  -8.4200   178.0   283.426657    1\n",
       "161 -39.3200  -7.2100 -37.0700  -8.4200  9476.0   272.957325    1\n",
       "162 -35.2400  -5.7800 -37.0700  -8.4200   984.0   432.773284    1\n",
       "163 -34.8761  -7.1011 -37.0700  -8.4200  2133.0   370.088972    1\n",
       "164 -35.0000  -7.5596 -37.0700  -8.4200  8771.0   335.259152    1\n",
       "165 -37.8000  -5.6500 -37.0700  -8.4200   917.0   337.190951    1\n",
       "..       ...      ...      ...      ...     ...          ...  ...\n",
       "223 -54.6400 -16.4695 -60.1166 -12.7166   490.0   716.166503    2\n",
       "226 -55.9100  -9.9000 -60.1166 -12.7166  4673.0   612.996033    2\n",
       "227 -64.4166 -12.4167 -60.1166 -12.7166  8530.0   686.910950    2\n",
       "228 -55.4506 -10.8173 -60.1166 -12.7166  1587.0   579.059784    2\n",
       "229 -55.4600 -11.8500 -60.1166 -12.7166  9035.0   513.201940    2\n",
       "331 -63.0400  -7.4639 -63.1300  -4.0800  5352.0   403.644727    1\n",
       "336 -60.9438  -2.6208 -63.1300  -4.0800  6091.0   440.590296    1\n",
       "337 -61.2975  -5.8122 -63.1300  -4.0800  3885.0   363.027081    1\n",
       "339 -60.6200  -3.2896 -63.1300  -4.0800  6824.0   437.320106    1\n",
       "341 -63.1300  -4.0800 -63.1300  -4.0800  2729.0    93.444232    1\n",
       "343 -64.7000  -3.3600 -63.1300  -4.0800  6992.0   197.943995    1\n",
       "344 -66.0916  -2.5138 -63.1300  -4.0800  5236.0   408.325168    1\n",
       "347 -62.9239  -0.9750 -63.1300  -4.0800  3741.0   475.671983    1\n",
       "326 -65.3499 -10.8000 -63.1300  -4.0800  3364.0   862.229375    2\n",
       "328 -57.6500  -6.2666 -63.1300  -4.0800  3020.0   831.922433    2\n",
       "329 -61.1277   1.8162 -63.1300  -4.0800   833.0   900.474063    2\n",
       "330 -60.2699  -6.9838 -63.1300  -4.0800  5805.0   560.426870    2\n",
       "332 -65.3597  -9.6954 -63.1300  -4.0800  1280.0   722.153924    2\n",
       "333 -67.8000  -9.9666 -63.1300  -4.0800  3841.0   901.665920    2\n",
       "334 -60.0000  -3.1000 -63.1300  -4.0800  2891.0   522.734324    2\n",
       "335 -68.6700  -9.0700 -63.1300  -4.0800  5446.0   889.647581    2\n",
       "338 -63.0800  -9.9396 -63.1300  -4.0800  1701.0   726.003764    2\n",
       "340 -57.7200  -3.3896 -63.1300  -4.0800  8774.0   803.466441    2\n",
       "342 -67.0833  -0.1332 -63.1300  -4.0800  6967.0   727.817230    2\n",
       "346 -58.4400  -3.1400 -63.1300  -4.0800  2241.0   717.799949    2\n",
       "348 -67.8019  -2.8727 -63.1300  -4.0800  9166.0   580.491363    2\n",
       "349 -69.8738  -6.6600 -63.1300  -4.0800  1592.0   860.594888    2\n",
       "350 -63.9000  -8.7500 -63.1300  -4.0800  1048.0   564.517094    2\n",
       "327 -72.6700  -7.6300 -63.1300  -4.0800  4811.0  1249.259244    3\n",
       "345 -60.6660   2.8161 -63.1300  -4.0800  3880.0  1045.975136    3\n",
       "\n",
       "[387 rows x 7 columns]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m.sort_values(['COG_LON','COG_LAT','SLA'],ascending=[False,False,True])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##  IV. Make-up the map displaying sites"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'plt' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-1-9af09ef76d35>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfigure\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfigsize\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m12\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m12\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0mmp\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mBasemap\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mllcrnrlon\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mORG_LON\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mllcrnrlat\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mORG_LAT\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0murcrnrlon\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmax\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mORG_LON\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0murcrnrlat\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmax\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mORG_LAT\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      3\u001b[0m \u001b[0mmp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdrawmapboundary\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfill_color\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'#A6CAE0'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mlinewidth\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      4\u001b[0m \u001b[0mmp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfillcontinents\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcolor\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'grey'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0malpha\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m0.4\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlake_color\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'grey'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      5\u001b[0m \u001b[0mmp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdrawcoastlines\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlinewidth\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m0.5\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mcolor\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'white'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mNameError\u001b[0m: name 'plt' is not defined"
     ]
    }
   ],
   "source": [
    "plt.figure(figsize=(12,12))\n",
    "mp = Basemap(llcrnrlon = min(m.ORG_LON)-10,llcrnrlat = min(m.ORG_LAT)-10, urcrnrlon = max(m.ORG_LON)+10,urcrnrlat = max(m.ORG_LAT)+10)\n",
    "mp.drawmapboundary(fill_color = '#A6CAE0',linewidth = 0)\n",
    "mp.fillcontinents(color = 'grey', alpha = 0.4, lake_color = 'grey')\n",
    "mp.drawcoastlines(linewidth = 0.5,color = 'white')\n",
    "\n",
    "plt.scatter(X[:,0],X[:,1],c=1,s=80,cmap='viridis')\n",
    "plt.scatter(c[:,0],X[:,1],c='white',s=200,alpha=1)\n",
    "\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
